package com.ruoyi.weixin.shop.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.weixin.shop.domain.vo.WxFloatButtonAddBo;
import com.ruoyi.weixin.shop.domain.vo.WxFloatButtonEditBo;
import com.ruoyi.weixin.shop.domain.vo.WxFloatButtonQueryBo;
import com.ruoyi.weixin.shop.domain.vo.WxFloatButtonVo;
import com.ruoyi.weixin.shop.service.IWxFloatButtonService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 悬浮按钮Controller
 *
 * @author ruoyi
 * @date 2021-07-20
 */
@Api(value = "悬浮按钮控制器", tags = {"悬浮按钮管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wx/shop/wxfloatbutton")
public class WxFloatButtonController extends BaseController {

	private final IWxFloatButtonService iWxFloatButtonService;

	/**
	 * 查询悬浮按钮列表
	 */
	@ApiOperation("查询悬浮按钮列表")
	@PreAuthorize("@ss.hasPermi('system:button:list')")
	@GetMapping("/list")
	public TableDataInfo<WxFloatButtonVo> list(@Validated WxFloatButtonQueryBo bo) {
		return iWxFloatButtonService.queryPageList(bo);
	}

	/**
	 * 导出悬浮按钮列表
	 */
	@ApiOperation("导出悬浮按钮列表")
	@PreAuthorize("@ss.hasPermi('system:button:export')")
	@GetMapping("/export")
	public AjaxResult<WxFloatButtonVo> export(@Validated WxFloatButtonQueryBo bo) {
		List<WxFloatButtonVo> list = iWxFloatButtonService.queryList(bo);
		ExcelUtil<WxFloatButtonVo> util = new ExcelUtil<WxFloatButtonVo>(WxFloatButtonVo.class);
		return util.exportExcel(list, "悬浮按钮");
	}

	/**
	 * 获取悬浮按钮详细信息
	 */
	@ApiOperation("获取悬浮按钮详细信息")
	@PreAuthorize("@ss.hasPermi('system:button:query')")
	@GetMapping("/{id}")
	public AjaxResult<WxFloatButtonVo> getInfo(@NotNull(message = "主键不能为空")
											   @PathVariable("id") Long id) {
		return AjaxResult.success(iWxFloatButtonService.queryById(id));
	}

	/**
	 * 新增悬浮按钮
	 */
	@ApiOperation("新增悬浮按钮")
	@PreAuthorize("@ss.hasPermi('system:button:add')")
	@PostMapping()
	public AjaxResult<Void> add(@Validated @RequestBody WxFloatButtonAddBo bo) {
		return toAjax(iWxFloatButtonService.insertByAddBo(bo) ? 1 : 0);
	}

	/**
	 * 修改悬浮按钮
	 */
	@ApiOperation("修改悬浮按钮")
	@PreAuthorize("@ss.hasPermi('system:button:edit')")
	@PutMapping()
	public AjaxResult<Void> edit(@Validated @RequestBody WxFloatButtonEditBo bo) {
		return toAjax(iWxFloatButtonService.updateByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 删除悬浮按钮
	 */
	@ApiOperation("删除悬浮按钮")
	@PreAuthorize("@ss.hasPermi('system:button:remove')")
	@DeleteMapping("/{ids}")
	public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
								   @PathVariable Long[] ids) {
		return toAjax(iWxFloatButtonService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
	}
}
